#include "sock_app.h"
#include <iostream>
#include "tcp_server.h"
#include "util/TimeEx.h"

using std::cerr;
using std::cout;
using std::endl;

bool quit_flag = false;

static void signal_handler(int signo){
    if (signo == SIGINT){
        printf("捕捉到SIGINT信号。\n");
        quit_flag = true;
    }else if (signo == SIGTERM){
        printf("捕捉到SIGTERM信号。\n");
        quit_flag = true;
    }else{
        printf("捕捉到信号%d。\n", signo);
    }
}

int main(int argc, char** argv){
    cout << "A simple tcp server." << endl;
    // 让signal_handler处理SIGINT和SIGTERM信号。
    signal(SIGINT, signal_handler);   
    signal(SIGTERM, signal_handler);

    CTCPServer::getInstance().start();
    while(!quit_flag)
        qcutil::Time::sleepMilliSeconds(100);
    CTCPServer::getInstance().stop();
    return 0;
}

